home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Text⁄Files / FaceLift / FaceLift Folder / FLFontOps.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-19  |  2.5 KB  |  133 lines  |  [TEXT/KAHL]

  1. # include    "TransSkel.h"
  2.  
  3. # include    "FLMaca.h"
  4. # include    "FaceLift.h"
  5.  
  6.  
  7. /*
  8.  * Query user whether to replace the current font list with the
  9.  * selected font, or just add them to the list.  Return false if
  10.  * Cancel clicked.  If Replace clicked, then warn user that the
  11.  * map will be destroyed (if it has been changed) and return false
  12.  * if he declines.  Otherwise return true.
  13.  *
  14.  * If Replace is selected, then the map and the font list are
  15.  * cleared as well as setting some state variables.  The map is
  16.  * really modified by clearing it, but that was ok'd by user, so is
  17.  * now considered clean (unmodified) - just like after New Map.
  18.  */
  19.  
  20. static Boolean
  21. ReplaceOrAdd (void)
  22. {
  23. typedef enum    /* alert button numbers */
  24. {
  25.     cancel = 1,
  26.     add,
  27.     replace
  28. };
  29. int    i;
  30.  
  31.     i = SkelAlert (replaceAlrtNum, SkelDlogFilter (nil, true),
  32.                                             skelPositionOnParentDevice);
  33.     SkelRmveDlogFilter ();
  34.     SkelDoUpdates ();
  35.  
  36.     if (i == cancel)
  37.         return (false);
  38.  
  39.     if (i == replace)
  40.     {
  41.         if (!DestroyWarn ())
  42.             return (false);
  43.         ClobberMap ();
  44.         ClearMapName ();
  45.         ResetFontList ();
  46.         mapModified = false;
  47.         undoOp = noUndo;
  48.     }
  49.     return (true);
  50. }
  51.  
  52.  
  53. /*
  54.  * Add the names of the FONT resources in the open resource files
  55.  * to the font list (or replace the list with those fonts). */
  56.  
  57. void
  58. ResourceFonts (Boolean ask)
  59. {
  60. short    i;
  61. short    fNum, nFonts;
  62. Str255    fontName;
  63. MenuHandle    m;
  64.  
  65.     if (ask)
  66.     {
  67.         if (ReplaceOrAdd () == false)
  68.             return;
  69.     }
  70.  
  71.     m = NewMenu (tempMenuNum, "\p");
  72.     AddResMenu (m, 'FONT');
  73.     nFonts = CountMItems (m);
  74.     for (i = 1; i <= nFonts; ++i)
  75.     {
  76.         GetItem (m, i, fontName);
  77.         GetFNum (fontName, &fNum);
  78.         if (!SetFontSpec (fNum, fontName))
  79.             break;
  80.     }
  81.     SyncFontSpecs ();
  82. }
  83.  
  84.  
  85. /*
  86.  * Add the fonts contained in the STR# whose id is fontStrNum
  87.  * to the font list (or replace the list with those fonts).
  88.  */
  89.  
  90. void
  91. StrFonts (Boolean ask)
  92. {
  93. Handle    h;
  94. short    i, j, len;
  95. short    nStrings;
  96. Str255    s;
  97. long    fNum;
  98.  
  99.     if (ask)
  100.     {
  101.         if (ReplaceOrAdd () == false)
  102.             return;
  103.     }
  104.  
  105.     h = GetResource ('STR#', fontStrNum);
  106.     nStrings = * (int *) *h;
  107.  
  108.     for (i = 0; i < nStrings; ++i)
  109.     {
  110.         GetIndString (s, fontStrNum, i + 1);
  111.         if (s[1] == '#')
  112.             continue;            /* comment - ignore */
  113.         len = s[0];
  114.         j = 1;
  115.         while (j <= len && s[j] != '/')
  116.             ++j;
  117.         if (j > len)    /* error */
  118.         {
  119.             NumToString ((long) fontStrNum, s);
  120.             Message3 ("\pA font list resource (STR# ", s,
  121.                         "\p) is messed up.");
  122.             break;
  123.         }
  124.         s[0] = j - 1;    /* length of numeric part */
  125.         StringToNum (s, &fNum);
  126.         s[j] = len - j;
  127.         if (!SetFontSpec ((int) fNum, &s[j]))
  128.             break;
  129.     }
  130.     ReleaseResource (h);
  131.     SyncFontSpecs ();
  132. }
  133.